package com.guchenbo.schedule;

import com.google.common.util.concurrent.Uninterruptibles;
import com.guchenbo.schedule.biz.SimpleQuartzJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.concurrent.TimeUnit;

/**
 * @author guchenbo
 * @date 2021/4/25
 */
public class QuartzQuickStart {

  public static void main(String[] args) {
    try {
      Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

      JobDetail jobDetail = JobBuilder.newJob(SimpleQuartzJob.class).
          withIdentity("demo","deG").build();

      Trigger trigger = TriggerBuilder.newTrigger().withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(5)).build();

      scheduler.start();
      scheduler.scheduleJob(jobDetail, trigger);

      Uninterruptibles.sleepUninterruptibly(60, TimeUnit.MINUTES);
      scheduler.shutdown();
    } catch (SchedulerException e) {
      e.printStackTrace();
    }
  }
}
